package com.tech.middle_ware.zk;

import org.apache.zookeeper.server.ServerConfig;
import org.apache.zookeeper.server.ZooKeeperServerMain;
import org.apache.zookeeper.server.admin.AdminServer;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;

import java.io.IOException;
import java.util.Properties;

/**
 * @author litianlin
 * @date 2023/11/30 10:42
 * @description:
 */
public class ZkMain {

    public static void main(String[] args) throws QuorumPeerConfig.ConfigException, IOException, AdminServer.AdminServerException {
        //属性设置
        Properties properties = new Properties();
        //数据目录
        properties.setProperty("dataDir", "/tmp");
        //服务端口
        properties.setProperty("clientPort", "2181");

        //属性转为节点配置
        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        //服务端配置
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        //运行Zookeeper服务
        ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
        zkServer.runFromConfig(configuration);
    }
}
